<template>
  <div class="el-form">
    <slot></slot>
  </div>
</template>

<script>
import emitter from './form-bus'
export default {
  name: 'ElForm',
  componentName: 'ElForm',
  mixins: [emitter],
  props: {
    width: Number,
    ruleForm: Object,
    model: Object
  },
  provide () {
    return {
      form: this
    }
  },
  created () {
    this.$on('haha', function (arg) {
      console.log(arg)
    })
  },
  mounted () {
    this.broadcast('ElFormInput', 'xixi', '嘻嘻')
  },
  methods: {
    submit (success, error) {
      this.broadcast('ElFormItem', 'vali')
      this.$nextTick(function () {
        const errorList = document.querySelector('.el-form').querySelectorAll('.vali-error')
        if (errorList.length === 0) {
          success()
        } else {
          error()
        }
      })
    }
  }
}
</script>
